package com.mallcai.bigdata.ladon.dpl.mapper.system;

import com.mallcai.bigdata.ladon.dpl.entity.system.UserSession;
import com.mallcai.bigdata.ladon.dpl.mapper.system.provider.UserSessionSqlProvider;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import static com.mallcai.bigdata.ladon.dpl.mapper.system.provider.UserSessionSqlProvider.TB_USER_SESSION;

/**
 * @author gst
 * @date 2019-12-30 20:36
 */
@Repository
public interface UserSessionMapper {


    @InsertProvider(type = UserSessionSqlProvider.class, method = "insert")
    public int insert(UserSession userSession);

    @Select({
            "SELECT * FROM " + TB_USER_SESSION + " WHERE user_id = #{userId}"
    })
    public UserSession isExist(@Param("userId") Long userId);

    @UpdateProvider(type = UserSessionSqlProvider.class, method = "update")
    public int update(UserSession userSession);

    @Select({
            "SELECT * FROM " + TB_USER_SESSION + " WHERE token = #{token}"
    })
    public UserSession findByToken(@Param("token") String token);

    @Delete({
            "DELETE FROM " + TB_USER_SESSION + " WHERE user_id = #{userId}"
    })
    public int deleteSession(@Param("userId") Long userId);

    @DeleteProvider(type = UserSessionSqlProvider.class, method = "deleteExpireToken")
    public int deleteExpireToken();
}
